<?php

namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;

use App\Http\Requests;
use Illuminate\Support\Facades\Input;
use Validator, Redirect, Session, Captcha;

class LoginController extends AdminController
{
    public function index()
    {
        return view('admin.login');
    }
    public function code() {
        return Captcha::create('default');
    }
    public function login(Request $request) {

        // dd(Input::get('cpt'));

        $messages = [
            'username.required'=>'用户名必填',
            'password.required'=>'密码必填',
            'cpt.required' => '请输入验证码',
            'cpt.captcha' => '验证码错误，请重试'
        ];
        $validator = Validator::make($request->all(), [
            'username' => 'required|max:255',
            'password' => 'required',
            "cpt" => 'required|captcha',
        ],$messages);

        if ($validator->fails()) {
            return redirect('admin/login/index')
                ->withErrors($validator)
                ->withInput();
        }

        dd('ok');



    }
}
